package com.renu.jdependencyanalyser.freemarker;

import freemarker.cache.StringTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;

public abstract class AbstractProcessor {
    //private ProjectInfo projectInfo;

    protected static Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);

    protected static StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();

    public AbstractProcessor() {
        configuration.setTemplateLoader(stringTemplateLoader);
    }

    protected  abstract Object getModel();

    protected  abstract Template getTemplate() throws IOException;

    protected  abstract  Writer getWriter();

    public final  String process() throws TemplateException, IOException {
        Template template = getTemplate();
        Object model = getModel();
        Writer writer = getWriter();
        template.process(model,writer);
        return writer.toString();
    }




}
